import 'dart:convert';

import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:flutter_screenutil/screen_util.dart';
import 'package:flutter/material.dart';
import 'package:study_online/entity/Course.dart';
import 'package:study_online/global/colors.dart';
import 'package:study_online/utils/richText.dart';

import '../StudyModel.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  const MyApp({Key key}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      builder: EasyLoading.init(),
      home: Scaffold(
        //appBar: AppBar(
        //  backgroundColor: Colors.black26,
        //  title: Text('container'),
        //),
        body: CourseIntroduceTab(),
      ),
    );
  }
}
class CourseIntroduceTab extends StatefulWidget {
  CourseIntroduceTab({Key key}) : super(key: key);

  @override
  _CourseIntroduceTabState createState() {
    return _CourseIntroduceTabState();
  }
}

class _CourseIntroduceTabState extends State<CourseIntroduceTab> with AutomaticKeepAliveClientMixin{
  @override
  void initState() {
    super.initState();
    _loadData();
  }

  @override
  void dispose() {
    super.dispose();
  }
  CourseDetail _course;
  Widget _titleWidget(value) {
    return Row(
      children: [
        SizedBox(width: ScreenUtil().setWidth(43),),
        Container(
          height: ScreenUtil().setHeight(40),
          width: ScreenUtil().setWidth(8),
          decoration: BoxDecoration(
            color: AppColors.primary,
            borderRadius: BorderRadius.all(Radius.circular(ScreenUtil().setWidth(4))),
          ),
        ),
        SizedBox(width: ScreenUtil().setWidth(22),),
        Text(
          value,
          style:TextStyle(
            color: Colors.black,
            fontWeight: FontWeight.bold,
            fontSize: ScreenUtil().setSp(40),
          ),
        )
      ],
    );
  }
  Widget _textWidget(value){
    return Container(
      padding: EdgeInsets.fromLTRB(ScreenUtil().setWidth(72), ScreenUtil().setHeight(48),
          ScreenUtil().setWidth(48), ScreenUtil().setHeight(56)),
      child: OPRichText(
        text: value,
        width: 620,
        textColor: AppColors.active,
      ),
    );
  }
  void _loadData() async {
    Response response=await getCourseInfoById(1);
    var responseData=json.decode(response.toString());
    setState(() {
      _course=CourseDetail.fromJson(responseData);
    });
  }
  @override
  Widget build(BuildContext context) {
    ScreenUtil.init(
      BoxConstraints(
          maxWidth: MediaQuery
              .of(context)
              .size
              .width,
          maxHeight: MediaQuery
              .of(context)
              .size
              .height),
      designSize: Size(1080, 2340),
    );
    if(_course==null){
      return Container(
        height: 0,
        width: 0,
      );
    }
    else{
     return ListView(
        children: [
          SizedBox(height: ScreenUtil().setHeight(20),),
          _titleWidget('授课老师'),
          _textWidget(_course.teaIntr),
          _titleWidget('课程简介'),
          _textWidget(_course.couIntro),
          _titleWidget('课程目标'),
          _textWidget(_course.couObj),
        ],
      );
    }
  }

  @override
  // TODO: implement wantKeepAlive
  bool get wantKeepAlive => true;
}

